import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author 12629
 * @Description：
 */
class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
        this.val = val;
    }
}
public class Test {
    public static void main(String[] args) {

    }
    public ArrayList<ArrayList<Integer>> Print (TreeNode pRoot) {

        ArrayList<ArrayList<Integer>> ret = new ArrayList<>();

        if(pRoot == null) {
            return ret;
        }

        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(pRoot);

        boolean flg = true;
        while(!queue.isEmpty()) {
            int size = queue.size();
            ArrayList<Integer> tmp = new ArrayList<>();
            while(size != 0) {
                TreeNode cur = queue.poll();
                tmp.add(cur.val);
                if(cur.left != null) {
                    queue.offer(cur.left);
                }
                if(cur.right != null) {
                    queue.offer(cur.right);
                }
                size--;
            }
            if(flg) {
                flg = false;
            }else {
                Collections.reverse(tmp);
                flg = true;
            }
            ret.add(tmp);
        }

        return ret;
    }
}
